#include <stdio.h>
#include <string.h>
#include "suivi_personnel.h"
#include "gestion_personnel.h"
#include "menu.h"

int transferer (FILE *EVENT,str M[100][100] ,int *n)
{
int i,find,m,pos,j;
char ch1[30]; eve p; int T[100];

EVENT = fopen("event.txt" , "r" );
(*n)=1; for (i=0;i<100;i++) T[i]=2; //inisialisation de nbr de colonne par ligne
	for (i=0;i<100;i++)
	{for (j=0;j<100;j++) {strcpy(M[i][j].ch,"");}}
	 
while (!feof(EVENT)) //remplissage
{
	fscanf(EVENT,"%s	%d		%s",p.TIME,&(p.IM),p.CAPT);
	find = 0; j=0;
	sprintf(ch1,"%d",(p.IM)); 
	
	
	while (find == 0 && j<(*n)) 
	{
	if (strcmp(M[j][0].ch,ch1) == 0) {find=1;pos=j;}
	j++;
	}
	if (find == 0) {strcpy(M[*n][0].ch,ch1);strcpy(M[*n][1].ch,p.CAPT);(*n)++;}
	if (find != 0) {strcpy(M[pos][T[pos]].ch,p.CAPT);T[pos] = T[pos]+1;}
	
}
strcpy(M[pos][T[pos]-1].ch,"");

for (i = 0 ; i<(*n) ; i++) 
{
j=0;printf("\n* ");
while (strlen(M[i][j].ch) != 0) {printf("%s |",M[i][j].ch);j++;}
}

	
return(0);
}

int test_entrer(str M[100][100],int n)
{
int test,i,j,c;
for (i = 0 ; i<n ; i++)
{
	j=1;
	while (strlen(M[i][j].ch) != 0)
	{
		if ( strcmp(M[i][j].ch,"E01") == 0 && (M[i][0].ch)[0] != '3') 
		{
		test = 0;
		for (c = 1 ; c<j ; c++)
		if (strcmp(M[i][c].ch,"C01") == 0) {test =1;}
		if (test == 0) {printf("\nALERTE le Personnel %s n\'a pas porté de combinaison de sécurité",M[i][0].ch);}
		}
	j++;}
}

return(0);
}

int test_sortie(str M[100][100],int n)
{int test,i,j;
for (i = 1 ; i<n ; i++)
	{j = 1; 
		while (strlen(M[i][j].ch) != 0)
		{
		if (M[i][0].ch[0] != '3' && ( strcmp(M[i][j].ch,"S01") == 0 && strcmp(M[i][j-3].ch,"L01") != 0 && strcmp(M[i][j-2].ch,"C02")!=0 && strcmp(M[i][j-1].ch,"I01") != 0)) {printf("\nALERTE le Personnel %s a fait un erreur dans la Sortie du centre d isolation",M[i][0].ch);}
		j++;}
	}

return(0);
}

int test_comb(str M[100][100],int n)
{int test,i,j;

for (i = 1 ; i<n ; i++)
{j = 1; 
	while (strlen(M[i][j].ch) != 0)
	{
	if (M[i][0].ch[0] != '3')
	if (strcmp(M[i][j].ch,"V01") == 0 && (strcmp(M[i][j-1].ch,"L02") != 0 || strcmp(M[i][j-2].ch,"I01") != 0)) {printf("\nALERTE le Personnel %s a fait un erreur dans le lavage des main et le passage au bain de chlore",M[i][0].ch);}; 
	j++;}
}
return(0);
}

int test_douche(str M[100][100],int n)
{int i,j;
for (i = 1 ; i<n ; i++)
{j = 1;	
	while(strlen(M[i][j].ch) != 0)
	{
	if (strcmp(M[i][j].ch,"B01") == 0 && strcmp(M[i][j-1].ch,"D01") != 0 && M[i][0].ch[0] != '3') {printf("\nALERTE le Personnel %s a accedé au Bureau sans avoir faire un Douche",M[i][0].ch);}

	if (strcmp(M[i][j].ch,"M01") == 0 && strcmp(M[i][j-1].ch,"D01") != 0 && M[i][0].ch[0] != '3') {printf("\nALERTE le Personnel %s a accedé au Magasin sans avoir faire un Douche",M[i][0].ch);}

	j++;}
}
return(0);
}


int test_ebola(str M[100][100],int n)
{int i,j;
for (i = 1 ; i<n ; i++)
{j = 1;
	while(strlen(M[i][j].ch) != 0)
	{
	if (strcmp(M[i][j].ch,"Ebola") == 0 && M[i][0].ch[0] != '3') printf("\nALERTE le Personnel %s est propablement infécté du Ebola",M[i][0].ch);
	j++;}	
}
return(0);
}

int test_out(str M[100][100],int n)
{int i,j;
for (i = 1 ; i<n ; i++)
{j = 1;
	while(strlen(M[i][j].ch) != 0)
	{
	if (strcmp(M[i][j].ch,"Pout") == 0 && M[i][0].ch[0] != '3') printf("\nALERTE le personnel %s est sortie a travers la barriére de la Clinique",M[i][0].ch);
	j++;}	
}
return(0);
}

int test_patient(str M[100][100],int n)
{int i;
for (i = 1 ; i<n ; i++)
{if ((M[i][0].ch[0]) == '3') {printf("\nALERTE le patient %s a quitté le centre d\'isolation",M[i][0].ch);}
}
return(0);
}



